package com.itheima.demo4;

import java.util.Scanner;

public class ExceptionDemo2 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        GirlFriend gf = new GirlFriend();

        //捕获异常
        while (true) {
            try {
                System.out.println("请输入您女朋友的姓名");
                String s = sc.nextLine();
                gf.setName(s);
                System.out.println("请输入您女朋友的年龄");
                String s1 = sc.nextLine();
                int i = Integer.parseInt(s1);
                gf.setAge(i);
                break;
            } catch (NumberFormatException e) {
                System.out.println("年龄格式有误");
            } catch (RuntimeException e){
                System.out.println("姓名的长度或年龄的范围有误，请重新输入");
            }
        }




    }
}
